<template>
  <v-toolbar color="blue-grey-darken-3">
    <template v-slot:prepend>
      <div class="text-h7">教务管理系统</div>
    </template>

    <v-divider class="ms-3" inset vertical></v-divider>

    <v-spacer></v-spacer>

    <v-spacer></v-spacer>

    <v-toolbar-items>
      <v-divider vertical></v-divider>

      <v-btn variant="text" @click="selectPages(0)">学生</v-btn>

      <v-divider vertical></v-divider>

      <v-btn variant="text" @click="selectPages(1)">教师</v-btn>

      <v-divider vertical></v-divider>

      <v-btn variant="text" @click="selectPages(2)">课程</v-btn>

      <v-divider vertical></v-divider>

      <v-btn variant="text" @click="selectPages(3)">成绩</v-btn>

      <v-divider vertical></v-divider>

      <v-btn variant="text" @click="selectPages(4)">学院</v-btn>

      <v-divider vertical></v-divider>

      <v-btn variant="text" @click="selectPages(5)">班级</v-btn>
    </v-toolbar-items>

    <v-divider vertical></v-divider>

    <v-app-bar-nav-icon class="ms-2" ></v-app-bar-nav-icon>
  </v-toolbar>
  <stu v-if="pageSelected == 0"></stu>
  <teacher v-if="pageSelected == 1"></teacher>
  <course v-if="pageSelected == 2"></course>
  <score v-if="pageSelected == 3"></score>
  <dept v-if="pageSelected == 4"></dept>
  <classs v-if="pageSelected == 5"></classs>

</template>

<script>
import axios from "axios";
import stu from "./stu.vue";
import teacher from "./teacher.vue";
import course from "./course.vue";
import score from "./score.vue";
import dept from "./dept.vue";
import classs from "./classs.vue";

export default {
  components: {
    stu,
    teacher,
    course,
    score,
    dept,
    classs,
  },
  data() {
    return {
      search: "",
      pageSelected: -1,
      searchSid: "",
      searchSname: "",
      refresh: true,
      studentDialog: false,
      teacherDialog: false,
      courseDialog: false,
      scoreDialog: false,

      items: [],
      scores: [],
    };
  },
  methods: {
    selectPages(pageidx) {
      console.log("Clicked on page with index:", pageidx);
      this.pageSelected = pageidx;
      console.log("Updated pageSelected to:", this.pageSelected);
    },
    async test() {
      await axios({
        method: "get",
        url: "http://127.0.0.1:8000/admin/test",

      })
    },
    openDialog() {
      // 初始化编辑的学生信息
      if (this.pageSelected === 0) {
        this.studentDialog = true;
      } else if (this.pageSelected === 1) {
        this.teacherDialog = true;
      } else if (this.pageSelected === 2) {
        this.courseDialog = true;
      } else if (this.pageSelected === 3) {
        this.scoreDialog = true;
      }
      this.editedStudent = {
        sname: "",
        student_id: "",
        grade: "",
        sex: "",
        native_place: "",
        mobile_phone: "",
        dept_id: "",
      };
      (this.editedTeacher = {
        tname: "",
        staff_id: "",
        sex: "",
        professional_ranks: "",
        dept_id: "",
      }),
        (this.editedCourse = {
          course_id: "",
          course_name: "",
          credit: "",
          credit_hours: "",
          dept_id: "",
          dept_name: "",
        }),
        (this.editedScore = {
          student_id: "",
          sname: "",
          course_id: "",
          course_name: "",
          normal_score: "",
          test_score: "",
          total_score: "",
        });
      this.dialog = true;
    },
    saveChanges() {
      // 处理保存逻辑，可以将编辑后的学生信息保存到数据中
      // 还没写分开保存
      console.log("Saved changes:", this.editedStudent);
      console.log("Saved changes:", this.editedTeacher);
      console.log("Saved changes:", this.editedCourse);
      console.log("Saved changes:", this.editedScore);
      // 关闭对话框
      if (this.pageSelected === 0) {
        this.studentDialog = false;
      } else if (this.pageSelected === 1) {
        this.teacherDialog = false;
      } else if (this.pageSelected === 2) {
        this.courseDialog = false;
      } else if (this.pageSelected === 3) {
        this.scoreDialog = false;
      }
    },
    closeDialog() {
      // 关闭对话框
      if (this.pageSelected === 0) {
        this.studentDialog = false;
      } else if (this.pageSelected === 1) {
        this.teacherDialog = false;
      } else if (this.pageSelected === 2) {
        this.courseDialog = false;
      } else if (this.pageSelected === 3) {
        this.scoreDialog = false;
      }
    },
  },
};
</script>
